package com.栈.栈基础;

import java.util.Iterator;
import java.util.Stack;

public class ArrayStack<E>{
    private final E[] array;
    private int top = 0;

    @SuppressWarnings("all")
    public ArrayStack(int capacity) {
        this.array = (E[]) new Object[capacity];
    }

//    @Override
    public boolean push(E value) {
        if (isFull()) {
            return false;
        }
        array[top++] = value;
        return true;
    }


    public E pop() {
        if (isEmpty()) {
            return null;
        }
        return array[--top];
    }


    public E peek() {
        if (isEmpty()) {
            return null;
        }
        return array[top-1];
    }


    public boolean isEmpty() {
        return top == 0;
    }


    public boolean isFull() {
        return top == array.length;
    }

}